//package com.sxbbc.common.basics.files.fdfs;
//
//import java.io.File;
//import java.io.IOException;
//
//import org.csource.common.MyException;
//import org.csource.common.NameValuePair;
//import org.csource.fastdfs.StorageClient1;
//import org.csource.fastdfs.StorageServer;
//import org.csource.fastdfs.TrackerClient;
//import org.csource.fastdfs.TrackerServer;
//import org.springframework.web.multipart.MultipartFile;
//
//import com.sxbbc.common.basics.files.RestUploadFileInfo;
//
///**
// *
// * FastDFS文件服务
// * @author Wahyee
// * @version 1.0
// */
//public class FastDFSClient {
//
//	private static FastDFSClient client = null;
//
//	private FastDFSClient() {
//		super();
//	}
//
//	public static FastDFSClient getInstance() {
//		if (client == null) {
//			synchronized (FastDFSClient.class) {
//				if (client == null) {
//					client = new FastDFSClient();
//				}
//			}
//		}
//		return client;
//	}
//
//	/**
//	 *
//	 * 文件上传
//	 * @param file
//	 * @return
//	 * @author Wahyee
//	 * @throws IOException
//	 * @throws MyException
//	 */
//	public String uploadFile(MultipartFile file) throws IOException, MyException {
//			String fileExtName = file.getContentType().substring(file.getContentType().lastIndexOf("/") + 1) ;
//			return uploadFile(file, fileExtName);
//	}
//
//	/**
//	 *
//	 * 文件上传
//	 * @param file 文件
//	 * @param fileExtName 扩展名
//	 * @return
//	 * @throws IOException
//	 * @throws MyException
//	 * @author Wahyee
//	 */
//	public String uploadFile(MultipartFile file,String fileExtName) throws IOException, MyException {
//		TrackerClient tracker = new TrackerClient() ;
//		TrackerServer trackerServer = tracker.getConnection() ;
//		StorageServer storageServer = null ;
//		StorageClient1 client = new StorageClient1(trackerServer,storageServer) ;
//		NameValuePair[] metaList = new NameValuePair[3] ;
//		metaList[0] = new NameValuePair("fileName",file.getName()) ;
//		metaList[1] = new NameValuePair("fileExtName",fileExtName) ;
//		metaList[2] = new NameValuePair("fileLength",String.valueOf(file.getSize())) ;
//		String url = client.upload_file1(file.getBytes(),fileExtName, metaList) ;
//		trackerServer.close();
//		return url;
//	}
//
//	/**
//	 *
//	 * 文件上传
//	 * @param file
//	 * @return
//	 * @author Wahyee
//	 */
//	public RestUploadFileInfo uploadFile(File file) {
//		try {
//			String fileExtName = file.getName().substring(file.getName().lastIndexOf(".") + 1) ;
//			TrackerClient tracker = new TrackerClient() ;
//			TrackerServer trackerServer = tracker.getConnection() ;	// 取得服务器连接
//			StorageServer storageServer = null ;
//			StorageClient1 client = new StorageClient1(trackerServer,storageServer) ;
//			NameValuePair[] metaList = new NameValuePair[3] ;
//			metaList[0] = new NameValuePair("fileName",file.getName()) ;
//			metaList[1] = new NameValuePair("fileExtName",fileExtName) ;
//			metaList[2] = new NameValuePair("fileLength",String.valueOf(file.length())) ;
//			String fileId = client.upload_file1(file.getPath(), fileExtName, metaList) ;
//			trackerServer.close();
//			return RestUploadFileInfo.getInstance().getSuccess(fileId);
//		} catch (Exception e) {
//			e.printStackTrace();
//			return RestUploadFileInfo.getInstance().getFail("上传失败");
//		}
//	}
//}
